/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import Interfaces.Diaxeirish;
import Interfaces.ApparentModalI;
import Model.Artist;
import Model.Musicgroup;
import Model.Musicgroupmember;
import java.awt.Frame;
import static java.awt.event.KeyEvent.VK_ENTER;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.persistence.EntityManager;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JTable;
import src.ApparentModalC;
import src.General;
import src.SimpleDateFormatInputVerifier;
import src.TextMaxLengthTrimInputVerifier;

/**
 * Διαχείριση μουσικού συγκροτήματος
 *
 */
public final class DiaxeirishGroupJFrame extends javax.swing.JFrame implements Diaxeirish, ApparentModalI {

    private JFrame next = null;
    private GroupsTableJFrame caller;
    private General.ActionType actionType;
    private Musicgroup mGroup;//για περίπτωση διαχείρισης ActionType.Update παίρνει αντίγραφο του επιλεγμένου γκρουπ του πίνακα της καλούσας φόρμας και δεν γίνεται ποτέ managed. Χρησιμοποιείται η μέθοδος merge του entity manager
    private List<Artist> artistList;
    private List<Musicgroupmember> groupMembers;
    private final List<Musicgroupmember> oldMemberList;

    /**
     * Creates new form DiaxeirishGroupJFrame
     */
    public DiaxeirishGroupJFrame() {
        throw new UnsupportedOperationException();
    }

    /**
     * constructor overload
     *
     * @param caller
     * @param ac
     */
    public DiaxeirishGroupJFrame(GroupsTableJFrame caller, List<Musicgroupmember> oldMemberList, General.ActionType at) {
        initComponents();
        try {
            General.setWindowImage(this);
        } catch (Exception ex) {
        }
        this.caller = caller;
        this.actionType = at;
        this.oldMemberList = oldMemberList;
        this.mGroup = caller.getSelectedEntityClone();
        if (mGroup.getMusicgroupmemberList() == null) {
            mGroup.setMusicgroupmemberList(new ArrayList<>());
        }
        this.groupMembers = mGroup.getMusicgroupmemberList();
        this.assignArtistList();
        this.artistList = General.bindTableToObservableArtistList(this.artistList, this.jTable1);

        this.jTable1.getRowSorter().toggleSortOrder(0);
        //Ανάλογα με την περίπτωση διαχείρισης
        switch (actionType) {
            case Insert:
                this.setTitle(this.getTitle() + " - " + "Εισαγωγή");
                this.actionJButton.setText("Αποθήκευση");
                break;
            case Update:
                this.setTitle(this.getTitle() + " - " + "Μεταβολή");
                this.actionJButton.setText("Μεταβολή");
                this.setFormData();
                break;
            case Delete:
                this.setTitle(this.getTitle() + " - " + "Διαγραφή !");
                this.actionJButton.setText("Διαγραφή");
                this.setFormData();
                General.disableAllComponents(this.jPanel1);
                General.disableAllComponents(this.jPanel3);
                break;
            default:
                break;
        }
        //Θέτει τους InputVerifier για το input του χρήστη
        if (this.actionType != General.ActionType.Delete) {
            this.eponymiaJTextField.setInputVerifier(new TextMaxLengthTrimInputVerifier(this.eponymiaValidationJLabel, 50));
            this.formationDateJTextField.setInputVerifier(new SimpleDateFormatInputVerifier(this.formationDateValidationJLabel));
        }
        //Δεν επιτρέπει ενημερώσεις από τον χρήστη στις γραμμές
        General.setJTableNotEditable(jTable1);
        if (this.artistList.size() == 0) {
            this.disableDelete();
        }
    }

    public List<Musicgroupmember> getGroupMembers() {
        return this.groupMembers;
    }

    public List<Artist> getArtistList() {
        return this.artistList;
    }

    /**
     * Δημιουργεί τη λίστα καλλιτεχνών του συγκροτήματος από την
     * MusicgroupmemberList
     */
    private void assignArtistList() {
        artistList = new ArrayList<>();
        if (this.mGroup.getMusicgroupmemberList() != null) {
            for (Musicgroupmember m : this.mGroup.getMusicgroupmemberList()) {
                if (m.getArtistId() != null) {
                    artistList.add(m.getArtistId());
                }
            }
        }
    }

    public EntityManager getEm() {
        return this.caller.getEM();
    }

    public JTable getTable() {
        return this.jTable1;
    }

    public Musicgroup getGroup() {
        return this.mGroup;
    }

    public void disableDelete() {
        this.deleteArtistJButton.setEnabled(false);
    }

    public void enableDelete() {
        this.deleteArtistJButton.setEnabled(true);
    }

    @Override
    public void setFormData() {
        this.eponymiaJTextField.setText(this.mGroup.getMusicGroupName());
        this.formationDateJTextField.setText(General.dateFormater.format(this.mGroup.getFormationDate()));
    }

    @Override
    public boolean setEntiyFromFormData() {
        this.mGroup.setMusicGroupName(this.eponymiaJTextField.getText());
        try {
            this.mGroup.setFormationDate(General.dateFormater.parse(this.formationDateJTextField.getText()));
        } catch (ParseException ex) {
            General.showErrorMessage(ex.getMessage(), "Error", this);
            return false;
        }
        if (this.actionType == General.ActionType.Insert) {
            this.mGroup.setCreatedBy(General.strUserName);
            this.mGroup.setCreatedDate(new Date());
        }
        return true;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        actionJButton = new javax.swing.JButton();
        cancelJButton = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        eponymiaJLabel = new javax.swing.JLabel();
        formationDateJLabel = new javax.swing.JLabel();
        eponymiaJTextField = new javax.swing.JTextField();
        formationDateJTextField = new javax.swing.JTextField();
        eponymiaValidationJLabel = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        insertArtistJButton = new javax.swing.JButton();
        deleteArtistJButton = new javax.swing.JButton();
        formationDateValidationJLabel = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Διαχείριση μουσικού συγκροτήματος");
        setMinimumSize(new java.awt.Dimension(691, 409));

        actionJButton.setText("Αποθήκευση");
        actionJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                actionJButtonActionPerformed(evt);
            }
        });

        cancelJButton.setText("Ακύρωση");
        cancelJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelJButtonActionPerformed(evt);
            }
        });

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Στοιχεία συγκροτήματος"));
        jPanel1.setToolTipText("");

        eponymiaJLabel.setText("Επωνυμία");

        formationDateJLabel.setText("Ημ/νία δημιουργίας");

        eponymiaJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                eponymiaJTextFieldKeyPressed(evt);
            }
        });

        formationDateJTextField.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                formationDateJTextFieldKeyPressed(evt);
            }
        });

        eponymiaValidationJLabel.setText("(μέχρι 50 χαρακτήρες)");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder("Καλλιτέχνες"));

        jTable1.setAutoCreateRowSorter(true);
        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_ALL_COLUMNS);
        jTable1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jTable1);

        insertArtistJButton.setText("Εισαγωγή");
        insertArtistJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                insertArtistJButtonActionPerformed(evt);
            }
        });

        deleteArtistJButton.setText("Διαγραφή");
        deleteArtistJButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteArtistJButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(insertArtistJButton)
                        .addGap(6, 6, 6)
                        .addComponent(deleteArtistJButton)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 134, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(deleteArtistJButton)
                    .addComponent(insertArtistJButton))
                .addContainerGap())
        );

        formationDateValidationJLabel.setText("πχ 23/9/2014 (4 ψηφία για το έτος)");
        formationDateValidationJLabel.setToolTipText("");
        formationDateValidationJLabel.setAutoscrolls(true);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(5, 5, 5)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(eponymiaJLabel)
                            .addComponent(formationDateJLabel))
                        .addGap(30, 30, 30)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(eponymiaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(eponymiaValidationJLabel))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addComponent(formationDateJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 280, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(formationDateValidationJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(13, 13, 13)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(eponymiaJLabel)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(eponymiaJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(eponymiaValidationJLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(14, 14, 14)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(formationDateJLabel)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(1, 1, 1)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(formationDateJTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(formationDateValidationJLabel))))
                .addGap(18, 18, 18)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(actionJButton)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cancelJButton))
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cancelJButton)
                    .addComponent(actionJButton))
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents

    private void actionJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_actionJButtonActionPerformed
        if (this.actionType != General.ActionType.Delete) {
            if (!General.checkJTFieldsInputVerification(this.jPanel1, this.getTitle(), this)) {
                return;
            }
            try {
                if (!General.checkNotNulls(new Object[]{"Επωνυμία", "Ημ/νία δημιουργίας"}, new JComponent[]{this.eponymiaJTextField, this.formationDateJTextField}, this)) {
                    return;
                }
            } catch (Exception ex) {
                General.showErrorMessage(ex.getMessage(), "Error", this);
                return;
            }

            if (this.mGroup.getMusicgroupmemberList().size() < 2) {
                General.showWarningMessage("Το πλήθος των καλλιτεχνών πρέπει να είναι τουλάχιστον 2.", "Έλεγχος πλήθους μελών", this);
                return;
            }
        }
        switch (this.actionType) {
            case Delete:
                try {
                    General.deleteFromDB(this.mGroup.getMusicGroupId(), this.mGroup, this.caller.getEM());
                    this.caller.getEntityList().remove(this.mGroup);
                } catch (Exception e) {
                    General.safeRollback(this.caller.getEM());
                    General.showDbErrorMsgIf(e, this);
                    return;
                }
                this.caller.getEntityList().remove(this.mGroup);
                break;
            case Insert:
                try {
                    if (!this.setEntiyFromFormData()) {
                        return;
                    }
                    General.setCreated(this.groupMembers);
                    General.insertToDB(this.mGroup, this.caller.getEM());
                    this.caller.getEntityList().add(this.mGroup);
                    int index = this.caller.getEntityList().indexOf(this.mGroup);
                    General.selectModelRowNVisible(index, this.caller.getTable());
                } catch (Exception e) {
                    General.safeRollback(this.caller.getEM());
                    General.showDbErrorMsgIf(e, this);
                    return;
                }
                break;
            case Update:
                try {
                    if (!this.setEntiyFromFormData()) {
                        return;
                    }
                    //Εάν διαγράφτηκε ένα μέλος και μετά ξαναπροστέθηκε,τότε με κριτήτριο unique index [MusicGroupId,ArtistId]
                    //δίνουμε στην καινούργια εγγραφή το MusicGroupMemberId της παλιάς αφού στην ουσία πρόκειται για την ίδια
                    //εγγραφή, και έτσι αποφεύγουμε και exception για duplicate key value...
                    for (Musicgroupmember current : this.groupMembers) {
                        for (Musicgroupmember old : this.oldMemberList) {
                            if (current.getMusicGroupId().equals(old.getMusicGroupId())
                                    && current.getArtistId().equals(old.getArtistId())) {
                                current.setMusicGroupMemberId(old.getMusicGroupMemberId());
                                current.setCreatedBy(old.getCreatedBy());
                                current.setCreatedDate(old.getCreatedDate());
                            }
                        }
                    }
                    //Για τα καινούργια μέλη θέτει τα πεδία createdDate, createdBy
                    List<Musicgroupmember> created = new ArrayList<>();
                    for (Musicgroupmember mgm : this.groupMembers) {
                        if (mgm.getMusicGroupMemberId() == null) {
                            created.add(mgm);
                        }
                    }
                    General.setCreated(created);
                    //Αφαιρεί τα διαγραμμένα μέλη από το p. context
                    //(Περνάμε στην παράμετρο του remove το managed αντικείμενο με merge - την πρώτη φορά που θα
                    //πατηθεί αποθήκευση θα είναι managed αλλά αν κάτι δεν παέι καλά θα γίνει ditached)
                    for (Musicgroupmember old : this.oldMemberList) {
                        if (!this.groupMembers.contains(old)) {
                            this.caller.getEM().remove(this.caller.getEM().merge(old));
                        }
                    }
                } catch (Exception e) {
                    General.showErrorMessage(e.getMessage(), "Error", this);
                    return;
                }
                Musicgroup mg = null;
                try {
                    mg = this.caller.getEM().merge(this.mGroup);
                } catch (Exception e) {
                    General.showErrorMessage(e.getMessage(), "Error", this);
                    return;
                }
                try {
                    General.updateDB(this.caller.getEM());
                    this.caller.getEntityList().set(General.getSelectedRowModelIndex(this.caller.getTable()), mg);
                } catch (Exception e) {
                    General.safeRollback(this.caller.getEM());
                    // Αν το a δεν υπάρχει στο p. context (λογικά μόνο αν έγινε ditached με το rollback)
                    if (mg != null && !this.caller.getEM().contains(mg)) {
                        //ξαναπαίρνουμε την managed εκδοχή της εγγραφής πριν τις αλλαγές που έκανε ο χρήστης
                        mg = this.caller.getEM().find(Musicgroup.class, mg.getMusicGroupId());
                        if (mg == null) {
                            General.showErrorMessage("Άγνωστο πρόβλημα με τη βάση δεδομένων.Η εφαρμογή θα κλείσει/n"
                                    + "προκειμένου να αποκλειστεί η πιθανότητα απώλειας ή αλλοίωσης δεδομένων", "Error", this);
                            System.exit(1);
                        }
                        //Τελικά επαναφέρουμε της εγγραφή της προηγούμενης φόρμας του πίνακα άλμπουμ
                        //στην managed εκδοχή πριν τις αλλαγές του χρήστη
                        int index2 = this.caller.getEntityList().indexOf(this.mGroup);
                        this.caller.getEntityList().set(index2, mg);
                    }
                    General.showDbErrorMsgIf(e, this);
                    return;
                }
                break;
            default:
                break;
        }
        this.caller.enableDeleteUpdateIf();
        this.caller.disableDeleteUpdateIf();
        General.closeWindowX(this);
    }//GEN-LAST:event_actionJButtonActionPerformed

    private void cancelJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cancelJButtonActionPerformed
        General.closeWindowX(this);
    }//GEN-LAST:event_cancelJButtonActionPerformed

    private void eponymiaJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_eponymiaJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.formationDateJTextField.requestFocus();
        }
    }//GEN-LAST:event_eponymiaJTextFieldKeyPressed

    private void formationDateJTextFieldKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_formationDateJTextFieldKeyPressed
        if (evt.getKeyCode() == VK_ENTER) {
            this.eponymiaJTextField.requestFocus();
        }
    }//GEN-LAST:event_formationDateJTextFieldKeyPressed

    private void insertArtistJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_insertArtistJButtonActionPerformed
        AddArtistToGroupJFrame aa = new AddArtistToGroupJFrame(this);
        if (aa.isTableEmpty()) {
            General.showInfoMessage("Δεν υπάρχουν διαθέσιμοι καλλιτέχνες", "Έλεγχος διαθέσιμων καλλιτεχνών", this);
            return;
        }
        ApparentModalC.modalSetNextVisible(this, aa);
    }//GEN-LAST:event_insertArtistJButtonActionPerformed


    private void deleteArtistJButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteArtistJButtonActionPerformed
        if (!General.checkRowSelected(jTable1, "καλλιτέχνης", "καλλιτέχνη", this)) {
            return;
        }
        int selectedArtistIndex = General.getSelectedRowModelIndex(jTable1);
        Musicgroupmember mgm;
        Musicgroupmember selectedMgm = General.getGroupMemberByArtistID(this.groupMembers, artistList.get(selectedArtistIndex).getArtistId());
        this.groupMembers.remove(selectedMgm);
        this.artistList.remove(selectedArtistIndex);
        if (this.artistList.size() == 0) {
            this.disableDelete();
        }
    }//GEN-LAST:event_deleteArtistJButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishGroupJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishGroupJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishGroupJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(DiaxeirishGroupJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new DiaxeirishGroupJFrame().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton actionJButton;
    private javax.swing.JButton cancelJButton;
    private javax.swing.JButton deleteArtistJButton;
    private javax.swing.JLabel eponymiaJLabel;
    private javax.swing.JTextField eponymiaJTextField;
    private javax.swing.JLabel eponymiaValidationJLabel;
    private javax.swing.JLabel formationDateJLabel;
    private javax.swing.JTextField formationDateJTextField;
    private javax.swing.JLabel formationDateValidationJLabel;
    private javax.swing.JButton insertArtistJButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables

    @Override
    public Frame getCaller() {
        return this.caller;
    }

    @Override
    public Frame getNext() {
        return this.next;
    }

    @Override
    public void setCallersNextNull() {
        ((ApparentModalI) this.caller).setNext(null);
    }

    @Override
    public void setNext(Frame w) {
        this.next = (JFrame) w;
    }
}
